#ifndef DFRT_MEMORY_MANAGEMENT_H
#define DFRT_MEMORY_MANAGEMENT_H

#include <stdbool.h>
#include <stdlib.h>

#ifdef __cplusplus
extern "C" {
#endif


struct dfrt_mem_release_mesg {
    void * pageaddr;
    size_t size;
};
bool dfrt_mem_next_rls( struct dfrt_mem_release_mesg * msgbuf );

void * dfrt_mem_malloc( size_t s );
void dfrt_mem_free( void * ptr);

bool dfrt_mem_try_exclusive_acquire( void * ptr, size_t size);
void dfrt_mem_blocking_exclusive_acquire( void * prt, size_t size);

// TODO : take care of these header circular dependencies.
bool native_shm_is_acquired(void * vptr);
static inline bool dfrt_mem_page_is_acquired(void * vptr) {
    return native_shm_is_acquired(vptr);
}


void native_shm_allthread_barrier();
static inline void dfrt_mem_allthread_barrier() {
    native_shm_allthread_barrier ();
}


bool dfrt_mem_try_shared_acquire( void * ptr, size_t size);
void dfrt_mem_blocking_shared_acquire( void * prt, size_t size);

bool dfrt_mem_try_upgrade( void * ptr, size_t size);
void dfrt_mem_blocking_upgrade( void * prt, size_t size);
bool dfrt_mem_async_acquire(void * vptr, size_t size, bool exclusive );

void dfrt_mem_release(void * ptr);

void * dfrt_mem_get_global();
void dfrt_mem_set_global(void * ptr);

#ifdef __cplusplus
}
#endif

#endif

